/*
 * ----------------------------------------------------------
 * FILE         : PublicFunction.js
 * CREATEUSER   : Ricky Chiang
 * CREATEDATE   : 2006/9/4
 * FILENAME     : PublicFunction
 * DESCRIPTION  : js 共用方法
 * MODIFIES     : 
 * MODIFIER     : 
 * MODIFIEDDATE : 
 * COMMENT      : 
 * ----------------------------------------------------------
 */

document.onkeydown=function(){
    if (((event.keyCode == 8) &&                                                    //BackSpace 
         ((event.srcElement.type != "text" &&  
         event.srcElement.type != "textarea" &&  
         event.srcElement.type != "password" &&  
         event.srcElement.type != "file") || 
         event.srcElement.readOnly == true)) ||  
        ((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82)) ) ||    //CtrlN,CtrlR 
        (event.keyCode == 116)  || (event.keyCode == 122) || (event.shiftKey && event.keyCode==121)) {//F9,Shift+F10                                            //F5 
        event.keyCode = 0;  
        event.returnValue = false;  
    } 
    
    if(event.keyCode == 13){
	    	if(document.getElementById("goindex") != null){
	    		if(window.status=event.srcElement.id == "goindex"){

	    			for(var i = 0; i < document.all.length; i++){
	    				if(document.all(i).id == "goindex"){
	    					document.all(i+1).click();
	    					return false;
	    				}
	    			}
	    		}
	    	}
	 }
};


if (window.Event) 
  document.captureEvents(Event.MOUSEUP);
 
function nocontextmenu() 
{
 event.cancelBubble = true
 event.returnValue = false;
 
 return false;
}
 
function norightclick(e) 
{
 if (window.Event) 
 {
  if (e.which == 2 || e.which == 3)
   return false;
 }
 else
  if (event.button == 2 || event.button == 3)
  {
   event.cancelBubble = true
   event.returnValue = false;
   return false;
  }
 
}
document.oncontextmenu = nocontextmenu;  // for IE5+
document.onmousedown = norightclick;  // for all others

/**
 * 
 * @param cid     container id
 * @param url     動態網頁的網址
 * @param params  網頁參數
 * 
 *
 */
var process = null;
var DynamicLoadPage = function(cid, url, params, method) {
	try {
		$(cid).innerHTML = "&nbsp;";
	}
	catch(ex) {
	}

	try {
	  	  
	  if (isFramework == "Y") {
	    process.abort();
	  }		
	}
	catch(ex) {
	}
	
	try {
		var onFailed = function(request) {
			$(cid).innerHTML = "<span style='background-color:red;color:white'>Load Page Failed.....</span>";
		};
		var obj = new Ajax.Updater(cid, url, 
			{method: 'post', parameters: (params!=null)?params:"", evalScripts: true, onComplete : method, onFailure: onFailed }
		);
	}
	catch(ex) {
	}
	process = obj.transport;
};


/**
 * 
 * @param url     		動態網頁的網址
 * @param params			網頁參數
 * @param onComplete	Callback Method
 * 
 *
 */
function AjaxSubmit(url, params, onComplete) {
	
	var __params;
	var __response;
	var __exception;
	
	var ajaxReqOnComplete = function(request) {
		
		var paramElem = request.responseXML.selectSingleNode("//ajax-response/parameter");
		var respElem  = request.responseXML.selectSingleNode("//ajax-response/result");
		var excepElem = request.responseXML.selectSingleNode("//ajax-response/exception");

		eval("__params = " + paramElem.firstChild.nodeValue+";");
		
		try {
			eval("__response = " + respElem.firstChild.nodeValue+";");			
		}
		catch(E){
			__response = null;
		}				
		try{
			__exception = excepElem.firstChild.nodeValue;
		}
		catch(E){}
		
		return {parameters : __params, results : __response, exception : __exception};
	};
	
	var ajaxReq = new Ajax.Request(
		url,
		{method : "post", asynchronous : (onComplete!=null), parameters : params, onComplete : ((onComplete!=null)?function(request) { var a = ajaxReqOnComplete(request); onComplete.apply(this, [a.parameters, a.results, a.exception]); }:null) }
	);
	
	if (onComplete==null) {
		
		return ajaxReqOnComplete(ajaxReq.transport);
	}
}

/**
 * functionName: 用於打開共用視窗
 *
 * @param arguments[0]   共用視窗的類別  		
 *
 */
function openCommonWindow() {

	var oRtn =  new Object();
	
	switch ( arguments[0] ) {
		
		// 5/30 單位組織架構選單single	  
		case "org":	
			oRtn = window.showModalDialog("Common.OrgList.mvc",'',"dialogHeight:400px; dialogLeft:200px;dialogWidth:400px;dialogTop:250px;");
			break;
		
		// 5/30 產品別架構選單single
		case "product":	
			oRtn = window.showModalDialog("Common.ProductList.mvc",'',"dialogHeight:400px; dialogLeft:200px;dialogWidth:400px;dialogTop:250px;");
			break;
				
	}
	
	return oRtn;
}

/*
 * url:要提交的mvc
 * width:寬度
 * height:高度
 * 用來打開IReport報表
 */
function openIReport(params,width, height) {
	
	var url = "JasperViewer.jsp?argument="+params.toJSONString();

  // 'directories,location,menubar,resizable,toolbar'
	openCenteredWindow(url,(new Date()).getTime(),width,height);
	
	//openCenteredWindow(url,(new Date()).getTime(),width,height, true, true, 'resizable');
}


function openPDF(params) {	
	var url = "pdf?argument="+params.toJSONString();
	window.open(url, (new Date()).getTime());
}


// have two params ;iReportCmd: ireport submit commnad ;iReportFile: ireport file name
function iReportParams(iReportCmd,iReportFile) {	

	this.iReportCmd=iReportCmd;
	this.iReportFile=iReportFile;	
}

// clear all field
function ClearAll(){

	var elelist = document.forms[0].elements;

	for (var i=0;i<elelist.length;i++){
	
		if ( elelist[i].type.toLowerCase() == "text"){			
			elelist[i].value = "";
 		}
 		if ( elelist[i].type.toLowerCase() == "hidden"){			
			elelist[i].value = "";
 		}
 		else if ((elelist[i].type.toLowerCase()).substring(0,6) == "select") {
 			elelist[i].value = "";
 		}
	}	
	return false;
}


/*
 * 去首尾空格
 */
function trim(str)
{
	for(var i = 0 ; i<str.length && str.charAt(i)==" " ; i++ ) ;
	for(var j =str.length; j>0 && str.charAt(j-1)==" " ; j--) ;
	if(i>j) return ""; 
	return str.substring(i,j); 
}

/*
 * JS计算两个日期的间隔天数
 */
function DateDiff(sDate1, sDate2)
{ 
	//sDate1和sDate2是2002-12-18格式   
	var aDate, oDate1, oDate2, iDays   
	aDate = sDate1.split("-")   
	oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为12-18-2002格式   
	aDate = sDate2.split("-")   
	oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])   
	iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24) //把相差的毫秒数转换为天数   
	return iDays   
}   

/*
 * 将数据格式化为三位一撇
 */
function DataFormatDouble() {
	var result = null;

	// 如果是空直接返回
	if (arguments[0] == "" || arguments[0] == undefined || arguments[0] == null || arguments[0] == "0") {
	
		if (arguments[1] != undefined && arguments[1] == "I") {
			result = "0";
		}
		else {
			result = "0.000";
		}
	}
			
	// 四舍五入保存2位小数
	result = Math.round(arguments[0] * 1000) / 1000;

	return result;
}

/*
 * 将数据格式化为三位一撇
 */
function DataFormat() {
	var result = null;

	// 如果是空直接返回
	if (arguments[0] == "" || arguments[0] == undefined || arguments[0] == null || arguments[0] == "0") {
	
		if (arguments[1] != undefined && arguments[1] == "I") {
			result = "0";
		}
		else {
			result = "0.00";
		}
	}
			
	// 四舍五入保存2位小数
	var intValue = Math.round(arguments[0] * 100) / 100;

	var strValue = intValue + "";

	// 如果有小数点，格式化后加小数点返回
	if (strValue.indexOf(".") > 0) {
		var strNum = AddFormat(strValue.substring(0, strValue.indexOf(".")), 3, ",");
		result =  strNum + strValue.substring(strValue.indexOf("."), strValue.length);
	}
	else {

		// 如果是整数就直接格式化后返回
		result =  AddFormat(strValue, 3, ",");
	}

	// 若有需要, 强制添加 ".00"
	if (arguments[1] == "F") {
		if (result.indexOf(".") <= 0) {
			result += ".00"
		}
		else if(result.substring(result.indexOf(".")+1, result.length).length == 1) {
			result += "0"
		}

	}

	return result;
}

/*
 * 简单的字符串格式化
 *
 * @param arguments[0] : 需要进行格式化的字符串
 * @param arguments[1] : 进行格式化的 step
 * @param arguments[2] : 进行格式化的 字符
 */
function AddFormat() {
	var result = "";
	var strValue = arguments[0];
	var step = (arguments[1] != undefined) ? (arguments[1]) : (-1);
	var flag = (arguments[2] != undefined) ? (arguments[2]) : ("");

	for (var i = strValue.length; i > step; i -= step) {
		result = flag + strValue.substring(i - step, i) + result;
		strValue = strValue.substring(0, i - step);
	}

	return strValue + result;
}
/*
 * 简单的字符串格式化,加千位分隔符
 *
 * @param num 
 */
function  commafy(num,decimal)
{  
   num  =  num + '';
   var  re=/(-?\d+)(\d{3})/;
   var post = num.indexOf('.');
   if(post>=0){
      var  num1 = num.substr(0,post)+"";
	  var  num2 = num.substr(post+1,num.length-1)+"";
	  if(num1.length>3){
	     while(re.test(num1)){  
           num1=num1.replace(re,"$1,$2")+"";
         } 
	  }
      if(decimal==0){
		         num = num1;
	  }
	  if(decimal!=0){
		  if(decimal>num2.length){	
		       for(var i=0 ; i <decimal-num2.length; i++ ){
		             num2 = num2+'0';
		       }
	       }
	      num = num1+"."+num2 ;  
	  }           
   }
   else{
     if(num.length>3){
        while(re.test(num))
        {  
            num=num.replace(re,"$1,$2");
		     
        } 
     }
     var constr = '.';
     if(decimal!=0){
		     for(var i = 0 ; i < decimal;i++ ){
		            constr = constr+'0';
		     }
			 num = num + constr;
		}
   }  
   return  num; 
}



function  commaObj(obj,decim,integ,flag)
{  
   if(obj.value==''){
       return true;
   }
   if(!checkIsDecimal(obj.value,flag)){
       alert('金额格式不正确');
       obj.focus();
       return false;
   }
   var numvalue= obj.value;
   
   
		for( var i = 0; i<numvalue.length && numvalue.charAt(i)=="0" ; i++ ) ;
		
		
		  if(i==numvalue.length)
   		{	
   		
   			numvalue= '0';

		}else if( numvalue.indexOf('.')>0  ){
			
			
			for( var j = 0; j<numvalue.indexOf('.') && numvalue.charAt(j)=="0" ; j++ ) ;
	
			if(j==numvalue.indexOf('.'))
			{
				numvalue = numvalue.substring((i-1),numvalue.length); 
			
			}else {
				numvalue = numvalue.substring(i,numvalue.length); 
			
			}
		
		}
		
		else {
				numvalue = numvalue.substring(i,numvalue.length); 
		
   		}
   
   
   
   
   var flag = '';
   var postAdd = numvalue.indexOf('+');
   var postDinus = numvalue.indexOf('-');
   if(postAdd==0||postDinus==0){
       flag = numvalue.substr(0,1);
       numvalue = numvalue.substr(1,numvalue.length-1);
   }
   var post = numvalue.indexOf('.');
   if(post >= 0 ){
        if(post==0){
             alert('金额格式不正确!');
             return false;  
        }
        var intestr = numvalue.substr(0,post);
        intestr = commafyback(intestr)+'';
        var decistr = numvalue.substr(post+1,numvalue.length);
        if(intestr.length>parseInt(integ)){
            alert('整数部分不能超过'+integ+'位!');
            obj.focus();
            return false;
        }
        if(parseInt(decim)==0){
            alert('只能输入整数!');
            obj.focus();
            return false;
        }
        if(decistr.length>parseInt(decim)){
            alert('小数部分不能超过'+decim+'位!');
            obj.focus();
            return false;
        }
     }
     else{
       if(obj.value!=0&&numvalue!='0'){
           if(numvalue.length>integ){
              alert('整数部分不能超过'+integ+'位!');
              obj.focus();
              return false;  
           }
       }
     }
     var num =  commafyback(numvalue)+'';
     obj.value= flag+commafy(num,decim);
     return true;
}


//投资试算功能使用的格式化金额
//type  1,大于等于0  2,大于0
function  commaObjForInvest(obj,decim,integ,flag,type)
{  



   if(obj.value==''){
       return true;
   }
 	
 		var numvalue= obj.value;

		for( var i = 0; i<numvalue.length && numvalue.charAt(i)=="0" ; i++ ) ;
		
		
		 if(i==numvalue.length)
   		{	
   		
   			numvalue= '0';

		}else if( numvalue.indexOf('.')>0  ){
			
			
			for( var j = 0; j<numvalue.indexOf('.') && numvalue.charAt(j)=="0" ; j++ ) ;
	
			if(j==numvalue.indexOf('.'))
			{
				numvalue = numvalue.substring((i-1),numvalue.length); 
			
			}else {
				numvalue = numvalue.substring(i,numvalue.length); 
			
			}
		
		}
		
		else {
				numvalue = numvalue.substring(i,numvalue.length); 
		
   		}



   if(type==2&&numvalue==0){
   		 alert('请输入大于0的数字');
   		obj.focus();
	       return false;
   }
   
   
    if(numvalue.substr(0,1)=='-'){
	    if(!checkIsDecimal(numvalue.substr(1,numvalue.lenth),flag)){
	       alert('请输入数字');
	       obj.focus();
	       return false;
	   }else {
	   	   alert('请输入大于0的数字');
	       obj.focus();
	       return false;	
	   }
    
    }else {
    	if(!checkIsDecimal(numvalue,flag)){
	       alert('请输入数字');
	       obj.focus();
	       return false;
	   }
    }
   
  
  
   var flag = '';
   var postAdd = numvalue.indexOf('+');
   var postDinus = numvalue.indexOf('-');
   if(postAdd==0||postDinus==0){
       flag = numvalue.substr(0,1);
       numvalue = numvalue.substr(1,numvalue.length-1);
   }
   var post = numvalue.indexOf('.');
   if(post >= 0 ){
        if(post==0){
             alert('金额格式不正确!');
             return false;  
        }
        var intestr = numvalue.substr(0,post);
        intestr = commafyback(intestr)+'';
        var decistr = numvalue.substr(post+1,numvalue.length);
        if(intestr.length>parseInt(integ)){
            alert('整数部分不能超过'+integ+'位!');
            obj.focus();
            return false;
        }
        if(parseInt(decim)==0){
            alert('只能输入整数!');
            obj.focus();
            return false;
        }
        if(decistr.length>parseInt(decim)){
            alert('小数部分不能超过'+decim+'位!');
            obj.focus();
            return false;
        }
     }
     else{
       if(obj.value!=0&&numvalue!='0'){
           if(numvalue.length>integ){
              alert('整数部分不能超过'+integ+'位!');
              obj.focus();
              return false;  
           }
       }
     }
     var num =  commafyback(numvalue)+'';
     obj.value= flag+commafy(num,decim);
     return true;
}
		
		


//验证输入的是否为小数格式
function checkIsDecimal(str,flag){
     if(flag!=undefined&&flag!=null&&flag!=''){
	     var postAdd = str.indexOf('+');
         var postDinus = str.indexOf('-');
         if(postAdd>0||postDinus>0){
              return false;
		 }
	    if(postAdd==0||postDinus==0){
		    str=str.substr(1,str.length);
		 } 
	 }
     var str1="0123456789.,";
     var i=0;
     for (i=0; i<str.length;i++) {
         var onechar=str.substring(i,i+1);
         if (!(str1.indexOf(onechar)!= -1)){
               return false;
          }
     }

     var post = str.indexOf('.');
     if(post >= 0 ){
        var instr = str.substr(post+1,str.length);
        var str2 = ".,";
        for (i=0; i<instr.length;i++) {
           var onechar=instr.substring(i,i+1);
           if (str2.indexOf(onechar)>0){
                return false;
           }
        }
     }
     return true;  
}
/*
 * 简单的字符串格式化,去掉千位分隔符
 *
 * @param num 
 */
function  commafyback(num)
{  
   num = num+ '';
   if(num!=''){
       var flag = '';
       var postAdd = num.indexOf('+');
       var postDinus = num.indexOf('-');
       if(postAdd==0||postDinus==0){
           flag = num.substr(0,1);
           num = num.substr(1,num.length-1);
      }
      var x = num.split(',');
      return flag + x.join("")+'';
   }else{
      return '';
   }
   

}    

function  commaObjback(obj)
{  
   var x = obj.value.split(',');
   obj.value = parseFloat(x.join(""));
}    



/*
 * 验证身份证号合法性.
 */
function checkCustomUId(objCustomId) {
  var valueCustomId = objCustomId.value.toUpperCase();

	// 当为空时不验证
	if (valueCustomId == "") {
  	return true;
	}

	// 当存在 “!” 时去掉 “!”
  //if (valueCustomId.substring(0, 1) == "!") {
  	//valueCustomId = valueCustomId.substring(1);
  //}

	if (valueCustomId.length == 10) {
		return checkCustomUId_tw(valueCustomId, objCustomId);
	}
	else if (valueCustomId.length == 15) {
		return checkCustomUId_zh15(valueCustomId, objCustomId);
	}
	else if (valueCustomId.length == 18) {
		return checkCustomUId_zh18(valueCustomId, objCustomId);
	}
	else {
		return false;
	}
}

/*
 * 验证身份证号合法性 (tw).
 */
function checkCustomUId_tw(valueCustomId, objCustomId) {

  var firstCustomIdChar = valueCustomId.substring(0, 1);
  var checkCustomId = firstCustomIdChar + valueCustomId.substring(1, valueCustomId.length);

  // 10位字符验证.
	if (checkCustomId.length != 10) {
		objCustomId.focus();
		return false;
	}

  // 验证首位字符为 A~Z 之间
  if (!(firstCustomIdChar >= "A" && firstCustomIdChar <= "Z")) {
		objCustomId.focus();
    return false;
  }

  // 细部验证
  if (IdnoCheck(checkCustomId) == 'N') {
		objCustomId.focus();
    return false;
  }

  // 将首位字符转大写
  objCustomId.value = checkCustomId;

  return true;
}

/*
 * 验证身份证号合法性 (zh 15位).
 */
function checkCustomUId_zh15(valueCustomId, objCustomId) {
	return /^(\d+)?$/.test(valueCustomId);
}

/*
 * 验证身份证号合法性 (zh 18位).
 */
function checkCustomUId_zh18(valueCustomId, objCustomId) {

  var arrVerifyCode = [1,0,"X",9,8,7,6,5,4,3,2];
  var Wi = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
  var Checker = [1,9,8,7,6,5,4,3,2,1,1];

  var Ai = valueCustomId.substring(0,17);

  if (!/^\d+$/.test(Ai)) {
		objCustomId.focus();
  	return false;
  }

  var yyyy = Ai.slice(6,10), mm = Ai.slice(10,12)-1, dd = Ai.slice(12,14);

  var d=new Date(yyyy,mm,dd), now=new Date();
  var year=d.getFullYear(), mon=d.getMonth(), day=d.getDate();

  if (year!=yyyy || mon!=mm || day!=dd || d>now || year<1940) {
		objCustomId.focus();
  	return false;
  }

  for(var i=0,ret=0;i<17;i++) ret+=Ai.charAt(i)*Wi[i];

  Ai+=arrVerifyCode[ret %=11];

  return valueCustomId == Ai;
}

function IdnoCheck(idno)
{
  var FW,SW,nFW,checkmark;
  var che1,che2,che3,che4,che5,che6,che7,che8,che9,che10,che11;
  FW = idno.substr(0,1);//????????
  FW = FW.toUpperCase();//???????
  SW = idno.substr(1,1);//????? 1 or 2

  if (FW>="A" && FW<="Z" && (SW=="1" || SW=="2"))
  {
    switch(FW)
    {
      case "A":
        nFW = "10";
        break;
      case "B":
        nFW = "11";
        break;
      case "C":
        nFW = "12";
        break;
      case "D":
        nFW = "13";
        break;
      case "E":
        nFW = "14";
        break;
      case "F":
        nFW = "15";
        break;
      case "G":
        nFW = "16";
        break;
      case "H":
        nFW = "17";
        break;
      case "I":
        nFW = "34";
        break;
      case "J":
        nFW = "18";
        break;
      case "K":
        nFW = "19";
        break;
      case "L":
        nFW = "20";
        break;
      case "M":
        nFW = "21";
        break;
      case "N":
        nFW = "22";
        break;
      case "O":
        nFW = "35";
        break;
      case "P":
        nFW = "23";
        break;
      case "Q":
        nFW = "24";
        break;
      case "R":
        nFW = "25";
        break;
      case "S":
        nFW = "26";
        break;
      case "T":
        nFW = "27";
        break;
      case "U":
        nFW = "28";
        break;
      case "V":
        nFW = "29";
        break;
      case "W":
        nFW = "32";
        break;
      case "X":
        nFW = "30";
        break;
      case "Y":
        nFW = "31";
        break;
      case "Z":
        nFW = "33";
        break;
    }

    che1 = parseInt(nFW.substr(0,1),10)*1;
    che2 = parseInt(nFW.substr(1,1),10)*9;
      che3 = parseInt(idno.substr(1,1),10)*8;
    che4 = parseInt(idno.substr(2,1),10)*7;
    che5 = parseInt(idno.substr(3,1),10)*6;
    che6 = parseInt(idno.substr(4,1),10)*5;
    che7 = parseInt(idno.substr(5,1),10)*4;
    che8 = parseInt(idno.substr(6,1),10)*3;
    che9 = parseInt(idno.substr(7,1),10)*2;
    che10 = parseInt(idno.substr(8,1),10)*1;
    che11 = parseInt(idno.substr(9,1),10);
    checkmark = (che1+che2+che3+che4+che5+che6+che7+che8+che9+che10+che11)%10;
    if (checkmark!= 0)
    {
      return "N";
    }
    else
    {
      return "Y";
    }
  }
  else
  {
    return "N";
  }
}

// 验证年月 200701 / 20071
function DateCheckYYYYM(txtValue) {
	
	reg=/^\d{4}(0[1-9]|1[0-2]|[1-9])$/;
	
	if(!reg.test(txtValue)) {
		return false;
	}
	else {
		return true;
	}
}

// 验证年月 200701
function DateCheckYYYYMM(txtValue) {
	
	reg=/^\d{4}(0[1-9]|1[0-2])$/;
	
	if(!reg.test(txtValue)) {
		return false;
	}
	else {
		return true;
	}
}

// 验证24小时制 0000-2359
function TimeCheckHHMM(txtValue) {
	
	reg=/^([01][0-9]|[2][0-3])[0-5][0-9]$/;
	
	if(!reg.test(txtValue)) {
		return false;
	}
	else {
		return true;
	}
}

// 验证月日 0101
function DateCheckMMDD(txtValue) {

	reg=/^(((1[02]|0[13578])(0[1-9]|[12][0-9]|3[01]))|((1[1]|0[469])(0[1-9]|[12][0-9]|3[0]))|(0[2](0[1-9]|1[0-9]|2[0-9])))$/;
	
	if(!reg.test(txtValue)) {
		return false;
	}
	else {
		return true;
	}
}

// 格式月日 MD --> MMDD
function DateFormatMD(txtYearValue,txtMonthValue) {
	
	if(txtYearValue.length == 1) {
		txtYearValue = "0"+txtYearValue;
	}
	
	if(txtMonthValue.length == 1) {
		txtMonthValue = "0"+txtMonthValue;
	}
	
	return txtYearValue+txtMonthValue;
}

// 验证起日期不能大于止日期
function checkDateFromTo(fromDate, toDate) {

	fromDate = fromDate.replace(/(\/|:|\s)/mg, "");
	toDate = toDate.replace(/(\/|:|\s)/mg, "");
	
	if(fromDate.length > 0 && toDate.length > 0) {
		if(fromDate*1 > toDate*1) {
			return false;
		}
	}
	
	return true;
}

// check InvestRatio is equarl 100
function check_InvestRatio (tableid, labmsgid, IsNotEveRow, number, col, message) {
	var obj_table = document.getElementById(tableid);
	var obj_labmsg = document.getElementById(labmsgid);
	var sum = 0;
	
	var length_table = obj_table.rows.length;

	if (length_table == 1) {
		obj_labmsg.innerText = message;
		
		return false;
	}
	
	if(IsNotEveRow == "Y") {
		for (var i = 1; i < length_table; i += 2) {
			sum +=  parseInt(obj_table.rows[i].cells[col].innerText);	
		}
	}
	else {
		for (var i = 1; i < length_table; i++) {
			sum +=  parseInt(obj_table.rows[i].cells[col].innerText);	
		}
	}

	if (sum != number) {
		obj_labmsg.innerText = message;
		
		return false;
	}
	
	return true;
}



//验证输入的是否全是数字
function checkIsInteger(Str){
    Str=""+Str;
    RegularExp=/^[0-9]+$/;
    if (RegularExp.test(Str)) {
        return true;
    }
    else {
        return false;
    }
}


/* 判断是否为邮政编码 */ 

function f_check_zipcode(CODE)   
  {   
      if(!checkIsInteger(CODE)){ 
          return false;   
      }
      if(CODE.length!=6){   
          return false;   
      }   
    return true;   
} 
  
//6. 电话号码格式验证    
//函数名：fucCheckTEL     
//功能介绍：检查是否为电话号码     
//参数说明：要检查的字符串     
//返回值：1为是合法，0为不合法     
function fucCheckTEL(TEL)     
{     
	var i,j,strTemp;     
	strTemp="0123456789-()# ";     
	for (i=0;i<TEL.length;i++){     
		j=strTemp.indexOf(TEL.charAt(i));     
		if (j==-1){      
		  return false;     
		}     
	}          
	return true;     
}    
     
/* 
要求：一、电话号码由数字、"("、")"和"-"构成 
二、电话号码为3到8位 
三、如果电话号码中包含有区号，那么区号为三位或四位 
四、区号用"("、")"或"-"和其他部分隔开 
用途：检查输入的电话号码格式是否正确 
输入： 
strPhone：字符串 
返回： (^([0][1-9]{2,3}[-])?\d{3,8}(-\d{1,6})?$)|(^\([0][1-9]{2,3}\)\d{3,8}(\(\d{1,6}\))?$)|(^\d{3,8}$)
如果通过验证返回true,否则返回false 
*/ 
function f_check_phone(obj)    
{  
   var regu =/^(\d{3,4}-)?\d{7,9}$/;    
   var re = new RegExp(regu);   
   if (re.test( obj.value )) {   
     return true;   
   }    
   return false;   
}  

function checkPhone(obj){
	if(obj.value.length >20){
		return false;
	}
	return true;
}	 
    
//验证手机号
function f_check_mobileTelephone(TEL){
	if(!checkIsInteger(TEL)) {
  	return false;  	
	}
  if(!(TEL.substring(0,2)=="13"||TEL.substring(0,2)=="15")){
  	return false;  	
  }else if(TEL.length !=11){
  	return false;  
  }
  return true;
}	


//验证E-mail的格式
function checkMailFormat(EMAIL){
   Str = ""+EMAIL;
   RegularExp = /[a-z0-9]*@[a-z0-9]*\.[a-z0-9]+/gi
   if (RegularExp.test(EMAIL)){
       return true;
   }else{
       return false;
   }
}
//验证输入的内容必须字母
 function checkChracterStr(str) {
     var str1="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
     var i=0;
     for (i=0; i<str.length;i++) {
         var onechar=str.substring(i,i+1);
         if (!(str1.indexOf(onechar)!= -1)){
               return false;
          }
     }
     return true;
 }



//检查是否为合法的身份证号码
  function checkIdentifyCard(num){
      if(num ==''){
	    return true;
	  }
      else if(num.length==15||num.length==18){
	     if(num.length==15){
		    if(!checkIsInteger(num)){
				return false;
			}
		 }
		 if(num.length==18){
		     if(!checkIsInteger(num.substr(0,17))){
				return false;
			}
			if(!checkIsInteger(num.substr(17,1))&&num.substr(17,1)!='X'&&num.substr(17,1)!='x'){
				return false;
			}
		 }	      
	  }
	  else{
	      return false;
	  }
	  return true;
  }

//验证输入的内容必须为数字、字母或组合
 function checkNumStr(str) {
     var str1="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
     var i=0;
     for (i=0; i<str.length;i++) {
         var onechar=str.substring(i,i+1);
         if (!(str1.indexOf(onechar)!= -1)){
               return false;
          }
     }
     return true;
 }

 
 function getToday(){
      var today=new Date();
	  var intYear=today.getYear();
	  var intMonth=today.getMonth()+1;
	  var intDay=today.getDate();	          
	  var atime = intYear+'-'+(intMonth<10?"0"+intMonth:intMonth)+'-'+(intDay<10?"0"+intDay:intDay);
	  return atime;
 }
 
  
 function getTime(){
      var today=new Date();
	  var hour=today.getHours();
	  var minu=today.getMinutes();         
	  var atime = (hour<10?"0"+hour:hour)+''+(minu<10?"0"+minu:minu);
	  return atime;
 }
 
//判断输入的日期是否正确
function CheckDate(INDate)
{ 
	   if (INDate=="") {return true; }
	   subYY=INDate.substr(0,4)
	   if(isNaN(subYY) || subYY<=0){
	        return false;
	    }
	    //转换月份
	    if(INDate.indexOf('-',0)!=-1){ separate="-"}
	    else{ return false;}
	    area=INDate.indexOf(separate,0)
	    subMM=INDate.substr(area+1,INDate.indexOf(separate,area+1)-(area+1))
	    if(isNaN(subMM) || subMM<=0){
	          return false;
	     }
	     if(subMM.length<2){subMM="0"+subMM}
	     //转换日
	     area=INDate.lastIndexOf(separate)
	     subDD=INDate.substr(area+1,INDate.length-area-1)
		if(isNaN(subDD) || subDD<=0){
		   return false;
		}
		if(eval(subDD)<10){subDD="0"+eval(subDD)}
		NewDate=subYY+"-"+subMM+"-"+subDD
		if(NewDate.length!=10){return false;}
		if(NewDate.substr(4,1)!="-"){return false;}
		if(NewDate.substr(7,1)!="-"){return false;}
		var MM=NewDate.substr(5,2);
		var DD=NewDate.substr(8,2);
		if((subYY%4==0 && subYY%100!=0)||subYY%400==0){ //判断是否为闰年
		   if(parseInt(MM)==2){
		    if(DD>29){return false;}
		   }
		}else{
		   if(parseInt(MM)==2){
		    if(DD>28){return false;}
		   } 
		}
		var mm=new Array(1,3,5,7,8,10,12); //判断每月中的最大天数
		var flag = false;
		for(i=0;i< mm.length;i++){
		   if (parseInt(MM) == mm[i]){
		     if(parseInt(DD)>31){return false;}
		     else{flag=true; }
		   }
		}
		if(flag==false){if(parseInt(DD)>30){return false;}}
		if(parseInt(MM)>12){return false;}
		return true;
}

function getValidDate(INDate){
        subYY=INDate.substr(0,4);
		var separate="-";
		var area=INDate.indexOf(separate,0);
		var subMM=INDate.substr(area+1,INDate.indexOf(separate,area+1)-(area+1));
		if(subMM.length<2){subMM="0"+subMM;}
		area=INDate.lastIndexOf(separate);
		var subDD=INDate.substr(area+1,INDate.length-area-1);
		if(eval(subDD)<10){subDD="0"+eval(subDD);}
		var NewDate=subYY+"-"+subMM+"-"+subDD;
		return NewDate;
}

function isCheckDate(obj){
   var value = obj.inputNode.value;
   if(!CheckDate(value)){
	   return false;
   }else{
      if(obj.inputNode.value!=''){
         var newdate = getValidDate(obj.inputNode.value);
		 obj.inputNode.value = newdate;  
		 obj.valueNode.value = newdate;
      }
		 return true;
   }

} 

function compareDate(obj1,obj2){
   var start = obj1.inputNode.value;
   var end = obj2.inputNode.value;
   if(start!=''&&end!=''){
      if(start>end){
         return false;
      }
   }
   return true;
} 


 var optFlag = '0';
 function optSubmit(){
 	if(optFlag == '0'){
 		optFlag = '1';
 		return true;
 	}else{
 		alert("请不要频繁操作");
 		return false;
 	}
 }
 
////////////////////// Ajax级联菜单 START///////////////////////// 
var currentSort;
     //创建XMLHttpRequest对象       
    function createXMLHttpRequest() {
        if(window.XMLHttpRequest) { //Mozilla 浏览器
            return new XMLHttpRequest();
        }
        else if (window.ActiveXObject) { // IE浏览器
            try {
                return new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }
    }
    
    //发送请求函数
    function sendRequest(url, target) {
        var XMLHttpReq = createXMLHttpRequest();
        XMLHttpReq.open("GET", url, true);
        XMLHttpReq.onreadystatechange = function(){processResponse(XMLHttpReq,target)};//指定响应函数
        XMLHttpReq.setRequestHeader("If-Modified-Since","0");
        XMLHttpReq.send(null);  // 发送请求
    }
    // 处理返回信息函数
    function processResponse(XMLHttpReq,target) {
        if (XMLHttpReq.readyState == 4) { // 判断对象状态
            if (XMLHttpReq.status == 200) { // 信息已经成功返回，开始处理信息
                updateMenu(XMLHttpReq,target);
            } else { //页面不正常
                alert("您所请求的页面有异常。");
            }
        }
    }
    //更新菜单函数
    function updateMenu(XMLHttpReq,target) {
    	var xmldom = XMLHttpReq.responseXML.documentElement; 
      	var len = xmldom.childNodes.length; 

        /**下面是用innerHTML输出控件内容的一般用法**/
        //var subMenu = "";
        //for(var i = 0; i < res.length; i++) {
        //    subMenu = subMenu + "  " + res[i].firstChild.data + "";
        //}
        //currentSort.innerHTML = subMenu;
        var list = document.getElementById(target);
        list.options.length=0;
        list.add(new Option("请选择",""));
        for(var i=0;i<len;i++){
            list.add(new Option(xmldom.childNodes.item(i).childNodes.item(0).text,xmldom.childNodes.item(i).childNodes.item(1).text));
        }
    }
    // 创建级联菜单函数
    function showSubMenu(value,url,target) {
        //currentSort =document.getElementById(obj); 
        //currentSort.parentNode.style.display = "";
        
        sendRequest(url + value , target);
        
        /**下面这一句的作用是：每次选择后回到第一个选项**/
        //document.all.mli.options[0].selected=true;
    }

 ////////////////////// Ajax级联菜单 END/////////////////////////

  //判断两个日期的大小
 function cmpDate(date1,date2){
    if(date1!=''&&date2!=''){
        if(date1>date2){
            return false;
        }
    }
    return true;
 }
 //判断身份号与生日是否统一
function BirthToIdentify(birth,identify){
       birth = birth.substr(0,4)+''+birth.substr(5,2)+''+birth.substr(8,2);
	   if(identify.length==18){
	      identify = identify.substr(6,8);
		  if(identify!=birth){
		      return false;
		  }
	   }
	   if(identify.length==15){
	      identify = identify.substr(6,6);
		  birth = birth.substr(2,6)
		  if(identify!=birth){
		      return false;
		  }
	   }
	   return true;
}



	function splitSubString(string, count){
		if(string.length > count){
			document.write("<span title="+ string +">" + string.substring(0,count)+"...</span>");
		}else{
			document.write(string);
		}
	}

	function loadingMsg(message){
		if(message == null || message == ''){
			message = '加载中.....';
		}
  	 	var info='';
		var p=document.createElement("DIV");
		if (!info) info='';
		p.id="p";
		p.style.position="absolute";
		p.style.width=document.body.scrollWidth;
		p.style.height=(document.body.offsetHeight>document.body.scrollHeight)?'100%':document.body.scrollHeight;
		p.style.zIndex='998';
		p.style.top='0px';
		p.style.left='0%';
		p.style.backgroundColor="gray";
		p.style.opacity='0.5';
		p.style.filter="alpha(opacity=0)";
		document.body.appendChild(p);
		var p1=document.createElement("DIV");
		var top=parseInt(parseInt(document.body.scrollHeight)*0.25)+document.body.scrollTop;
		p1.style.position="absolute";
		p1.style.width="300px";
		p1.id="p1";
		var left=Math.ceil(((document.body.scrollWidth)-parseInt(p1.style.width.replace('px','')))/2)+document.body.scrollLeft;
		p1.style.height="200px";
		p1.style.zIndex='999'; 
		p1.style.top=top+'px';
		p1.style.left=left+'px';
		p1.style.border="0px solid red";
		var html="";
 		html+="<center>"
		html+="<div  style='width:210px; height:70px;background-color:#ededed;filter: Alpha(Opacity=80);z-index:20;border-left: 1px solid #b7b7b7;border-right: 1px solid #b7b7b7;border-bottom: 1px solid #b7b7b7;border-top: 1px solid #b7b7b7;'>";
		html+="<table width='100%' height='100%'><tr><td align='center' valign='middle' >";
		html+="<font style='FONT-SIZE: 12px; COLOR: #333'>" + message + "</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='../newimages/loading.gif'/>";
		html+="</td></tr></table>";
		html+="</div>"
		html+="</center>"

		document.body.appendChild(p1);
		p1.innerHTML=html;
		
	}

function strfill(str, maxlength, filledchar, position){
	var rtnStr = "";
	var maxlen = Number(maxlength);
	if(str.length>maxlength){
		return str;
	}else{
		var fillsize = maxlength-str.length;
		var fillstr = "";
		for(var i=fillsize;i>0;i--){
			fillstr = fillstr+filledchar;
		}
		if(position == '1'){  //from begin
			rtnStr = fillstr+str;
		}else if(position == '2'){  //from end
			rtnStr = str+fillstr;
		}
		return rtnStr;
	}
}
	